package com.Maykk.Demo01;

import javax.xml.ws.soap.Addressing;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Arrays;

/**
 * @ClassName: Demo01
 * @Description: TODO InetAddress 类练习
 * @Author: MaykkStar@163.com
 */
public class Demo01 {
    public static void main(String[] args) throws UnknownHostException {
        InetAddress star = InetAddress.getByName("Star");
        System.out.println(star);

        System.out.println("''''''''''''''''''''''''");
        InetAddress localHost = InetAddress.getLocalHost();
        System.out.println(localHost);

        System.out.println("''''''''''''''''''''''''");
        InetAddress[] stars = Inet4Address.getAllByName("Star");
        Arrays.stream(stars).forEach(System.out::println);

        System.out.println("''''''''''''''''''''''''");
        byte[] address = star.getAddress();
        InetAddress byAddress = InetAddress.getByAddress(address);
        System.out.println(Arrays.toString(address));
        System.out.println(byAddress);

        System.out.println("''''''''''''''''''''''''");
        // 获取 IP 名称
        System.out.println(star.getHostName());
        // 获取 IP 地址
        System.out.println(star.getHostAddress());
    }
}
